﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using Wpf.CommonTools.StaticExtension;

namespace Convertor
{
    /// <summary>
    /// PopMessage.xaml 的交互逻辑
    /// </summary>
    public partial class PopMessage : Window
    {
        MainWindow parentForm;

        public PopMessage()
        {
            InitializeComponent();
        }

        public PopMessage(MainWindow parentForm, string message)
            : this()
        {
            label1.Content = message;
            this.parentForm = parentForm;
        }

        private void ShowMessage()
        {
            this.Dispatcher.Invoke(new Action(() => { this.ShowDialog(); }));
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(new ThreadStart(alertFunction));
            th.IsBackground = true;
            th.Start();
        }

        private void alertFunction()
        {
            Thread.Sleep(2000);
            CloseAlertBox();
        }


        private void CloseAlertBox()
        {
            try
            {
                this.Dispatcher.Invoke(new Action(() => { this.Close(); }));
            }
            catch (Exception ex)
            {
            }
        }

        public static void PopAlertMessage(MainWindow parentForm, string message)
        {
            PopMessage popMessage = new PopMessage(parentForm, message);
            popMessage.SetCenterOfWindow(parentForm);
            popMessage.ShowDialog();
        }
    }

}
